﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//引入命名空间
using stwh_Common.DBUtility;
using System.Data.SqlClient;
using System.Data;

namespace stwh_Web
{
    public partial class getVisitCount : System.Web.UI.Page
    {
        public string NumType = "1";
        public string VisitCount = "0";

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                int num;
                string sessionID = this.Session.SessionID;
                string str2 = "www.shetbwg.com";
                string str3 = "index.aspx";
                string userHostAddress = base.Request.UserHostAddress;
                bool flag = true;
                DbHelperSQL.connectionString = PubConstant.GetConnectionString("ConnectionString", true);
                if (((base.Request["Type"] != null) && int.TryParse(base.Request["Type"], out num)) && ((num > 0) && (num < 0x3d)))
                {
                    this.NumType = base.Request["Type"];
                }
                if (this.Session["VisitLog"] == null)
                {
                    this.Session["VisitLog"] = new Dictionary<string, DateTime>();
                }
                Dictionary<string, DateTime> dictionary = (Dictionary<string, DateTime>)this.Session["VisitLog"];
                if (dictionary.ContainsKey(sessionID + "::" + str2 + "||:" + str3))
                {
                    DateTime time = dictionary[sessionID + "::" + str2 + "||:" + str3];
                    TimeSpan span = (TimeSpan)(DateTime.Now - time);
                    if (span.Seconds <= 5)
                    {
                        flag = false;
                    }
                }
                if (flag)
                {
                    SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier), new SqlParameter("@AccessTime", SqlDbType.DateTime), new SqlParameter("@IPAddress", SqlDbType.VarChar, 200), new SqlParameter("@SessionID", SqlDbType.VarChar, 100), new SqlParameter("@SiteName", SqlDbType.VarChar, 200), new SqlParameter("@PageName", SqlDbType.VarChar, 200) };
                    parameters[0].Value = Guid.NewGuid();
                    parameters[1].Value = DateTime.Now;
                    parameters[2].Value = userHostAddress;
                    parameters[3].Value = sessionID;
                    parameters[4].Value = str2;
                    parameters[5].Value = str3;
                    DbHelperSQL.RunProcedure("usp_InsertXCounterMain", parameters);
                    SqlParameter[] parameterArray2 = new SqlParameter[] { new SqlParameter("@SiteName", SqlDbType.VarChar, 200), new SqlParameter("@PageName", SqlDbType.VarChar, 200) };
                    parameterArray2[0].Value = str2;
                    parameterArray2[1].Value = str3;
                    DbHelperSQL.RunProcedure("usp_CountRcd", parameterArray2);
                    if (dictionary.ContainsKey(sessionID + "::" + str2 + "||:" + str3))
                    {
                        dictionary[sessionID + "::" + str2 + "||:" + str3] = DateTime.Now;
                    }
                    else
                    {
                        dictionary.Add(sessionID + "::" + str2 + "||:" + str3, DateTime.Now);
                    }
                }
                DataSet set = DbHelperSQL.Query("Select [Count] from tbl_XCounter_Ct where PageName='" + str3 + "' and SiteName='" + str2 + "'", (SqlParameter[])null);
                if (set.Tables[0].Rows.Count != 0)
                {
                    this.VisitCount = set.Tables[0].Rows[0][0].ToString();
                }
            }
            catch (Exception)
            {
            }
        }
    }
}